package com.black.common.core.domain.page;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * 分页请求参数对象
 */
@Getter
@Setter
public abstract class PageAbstructReq {
    /**
     * 当前记录起始索引
     */
    @ApiModelProperty(value = "分页第几页", position = 1, required = true)
    private Integer pageNum = 1;

    /**
     * 每页显示记录数
     */
    @ApiModelProperty(value = "每页显示记录数", position = 2, required = true)
    private Integer pageSize = 10;

    /**
     * 排序列
     */
    @ApiModelProperty(value = "排序列", position = 3)
    private String orderByColumn;

    /**
     * 排序的方向desc或者asc
     */
    @ApiModelProperty(value = "排序的方向desc或者asc", position = 4)
    private String isAsc = "asc";

    /**
     * 生成排序字符串
     *
     * @return
     */

    @ApiModelProperty(hidden = true)
    public abstract String getOrderBy();

    /**
     * 设定排序的方向
     *
     * @param isAsc
     */
    public void setIsAsc(String isAsc) {
        if (StrUtil.isNotEmpty(isAsc)) {
            // 兼容前端排序类型
            if ("ascending".equals(isAsc)) {
                isAsc = "asc";
            } else if ("descending".equals(isAsc)) {
                isAsc = "desc";
            }
            this.isAsc = isAsc;
        }
    }

}
